﻿// 功能：MzFC 中的 DrawHelper
// 描述：
// 作者：温伟鹏
// 日期：2010/5/21 0:09:42

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;

namespace MeizuSDK.Drawing
{
    /// <summary>
    /// 绘图帮助类。MzFC 中的 DrawHelper
    /// </summary>
    public sealed class MzDrawHelper
    {
        #region Color相关
        /// <summary>
        /// 根据R、G、B获取COLORREF值
        /// </summary>
        /// <param name="r">红</param>
        /// <param name="g">绿</param>
        /// <param name="b">蓝</param>
        /// <returns>返回COLORREF的值</returns>
        [DllImport("MZFCWrapper.dll", SetLastError = true, EntryPoint = "GetRGB")]
        public static extern int GetRGB(byte r, byte g, byte b);
        /// <summary>
        /// 返回Color所表示的COLORREF的值
        /// </summary>
        /// <param name="color"></param>
        /// <returns>如果Color为空，则返回-1</returns>
        public static int GetRGB(Color color)
        {
            if (color == Color.Empty)
                return -1;

            return GetRGB(color.R, color.G, color.B);
        }
        /// <summary>
        /// 获取COLORREF中的R值
        /// </summary>
        /// <param name="rgb"></param>
        /// <returns></returns>
        [DllImport("MZFCWrapper.dll", SetLastError = true, EntryPoint = "GetRValueEx")]
        public static extern byte GetRValue(int rgb);
        /// <summary>
        /// 获取COLORREF中的G值
        /// </summary>
        /// <param name="rgb"></param>
        /// <returns></returns>
        [DllImport("MZFCWrapper.dll", SetLastError = true, EntryPoint = "GetGValueEx")]
        public static extern byte GetGValue(int rgb);
        /// <summary>
        /// 获取COLORREF中的B值
        /// </summary>
        /// <param name="rgb"></param>
        /// <returns></returns>
        [DllImport("MZFCWrapper.dll", SetLastError = true, EntryPoint = "GetBValueEx")]
        public static extern byte GetBValue(int rgb);
        /// <summary>
        /// 将RGB值转化为Color结构
        /// </summary>
        /// <param name="rgb"></param>
        /// <returns></returns>
        public static Color ConvertRgbToColor(int rgb)
        {
            byte r = GetRValue(rgb);
            byte g = GetGValue(rgb);
            byte b = GetBValue(rgb);

            return Color.FromArgb(r, g, b);
        }
        #endregion

        /// <summary>
        /// 绘制位图
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcDst"></param>
        /// <param name="hBmp">HBITMAP</param>
        /// <param name="prcSrc"></param>
        /// <returns></returns>
        [DllImport("MZFCWrapper.dll", EntryPoint = "BitmapBltEx", SetLastError = true)]
        private static extern bool BitmapBlt(IntPtr hdcDst, ref RECT prcDst, IntPtr hBmp, ref RECT prcSrc);
        /// <summary>
        /// 绘制位图
        /// </summary>
        /// <param name="g"></param>
        /// <param name="prcDst"></param>
        /// <param name="hBmp">HBITMAP</param>
        /// <param name="prcSrc"></param>
        /// <returns></returns>
        public static bool BitmapBlt(Graphics g, Rectangle prcDst, IntPtr hBmp, Rectangle prcSrc)
        {
            IntPtr hdc = g.GetHdc();

            try
            {
                RECT rect1 = RECT.FromRectangle(prcDst);
                RECT rect2 = RECT.FromRectangle(prcSrc);

                return BitmapBlt(hdc, ref rect1, hBmp, ref rect2);
            }
            catch
            {
                return false;
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }
        }
        /// <summary>
        /// 绘制 COLORKEY 位图。将位图中指定颜色绘制为透明色
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcDst"></param>
        /// <param name="hBmp"></param>
        /// <param name="prcSrc"></param>
        /// <param name="clrKey"></param>
        /// <returns></returns>
        [DllImport("MZFCWrapper.dll", EntryPoint = "BitmapTransBltEx", SetLastError = true)]
        private static extern bool BitmapTransBlt(IntPtr hdcDst, ref RECT prcDst, IntPtr hBmp, ref RECT prcSrc, int clrKey);
        /// <summary>
        /// 绘制 COLORKEY 位图。将位图中指定颜色绘制为透明色
        /// </summary>
        /// <param name="g"></param>
        /// <param name="prcDst"></param>
        /// <param name="hBmp"></param>
        /// <param name="prcSrc"></param>
        /// <param name="clrKey"></param>
        /// <returns></returns>
        public static bool BitmapTransBlt(Graphics g, Rectangle prcDst, IntPtr hBmp, Rectangle prcSrc, Color clrKey)
        {
            IntPtr hdcDst = g.GetHdc();

            try
            {
                RECT rect1 = RECT.FromRectangle(prcDst);
                RECT rect2 = RECT.FromRectangle(prcSrc);

                return BitmapTransBlt(hdcDst, ref rect1, hBmp, ref rect2, GetRGB(clrKey));
            }
            catch
            {
                return false;
            }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }
        /// <summary>
        /// 把目的矩形置于参考矩形的中间
        /// </summary>
        /// <param name="prcRef"></param>
        /// <param name="prcDst"></param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "CenterRectEx", SetLastError = true)]
        private static extern void CenterRect(ref RECT prcRef, ref RECT prcDst);
        /// <summary>
        /// 把目的矩形置于参考矩形的中间
        /// </summary>
        /// <param name="prcRef">参考矩形</param>
        /// <param name="prcDst">目的矩形</param>
        public static void CenterRect(Rectangle prcRef, ref Rectangle prcDst)
        {
            try
            {
                RECT rect1 = RECT.FromRectangle(prcRef);
                RECT rect2 = new RECT();

                CenterRect(ref rect1, ref rect2);

                prcDst = Rectangle.FromLTRB(rect2.Left, rect2.Top, rect2.Right, rect2.Bottom);
            }
            catch { }
        }

        /// <summary>
        /// 删除缓冲的Mask位图
        /// </summary>
        [DllImport("MZFCWrapper.dll", EntryPoint = "ClearCachedRoundMaskBitmapsEx", SetLastError = true)]
        public static extern void ClearCachedRoundMaskBitmaps();

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="hdcDst"></param>
        ///// <param name="rect"></param>
        ///// <param name="CopyRect"></param>
        ///// <param name="nRadius"></param>
        ///// <param name="hbmp"></param>
        ///// <param name="rcBmp"></param>
        ///// <param name="bkCr"></param>
        ///// <param name="crTrans"></param>
        //[DllImport("MZFCWrapper.dll", EntryPoint = "DrawBmpRoundRect2Ex", SetLastError = true)]
        //public static extern void DrawBmpRoundRect2(IntPtr hdcDst, RECT rect, RECT CopyRect, int nRadius,
        //    IntPtr hbmp, RECT rcBmp, int bkCr, int crTrans);

        /// <summary>
        /// 画颜色线
        /// </summary>
        /// <param name="hdcDst">设备上下文句柄</param>
        /// <param name="x1">起点X坐标</param>
        /// <param name="y1">起点Y坐标</param>
        /// <param name="x2">终点X坐标</param>
        /// <param name="y2">终点Y坐标</param>
        /// <param name="clr">颜色</param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawColorLineEx", SetLastError = true)]
        private static extern void DrawColorLine(IntPtr hdcDst, int x1, int y1, int x2, int y2, int clr);
        /// <summary>
        /// 画颜色线
        /// </summary>
        /// <param name="g">绘图图面</param>
        /// <param name="p1">起始点</param>
        /// <param name="p2">终止点</param>
        /// <param name="clr">线条颜色</param>
        public static void DrawColorLine(Graphics g, Point p1, Point p2, Color clr)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                DrawColorLine(hdcDst, p1.X, p1.Y, p2.X, p2.Y, GetRGB(clr));
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }

        }

        /// <summary>
        /// 绘制渐变色背景——银色至白色
        /// </summary>
        /// <param name="hdcDst">设备上下文句柄</param>
        /// <param name="prcDst">待绘背景所在矩形</param>
        /// <param name="xOffset"></param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawGradientBg_SilverWhite_480Ex", SetLastError = true)]
        private static extern void DrawGradientBg_SilverWhite_480(IntPtr hdcDst, ref RECT prcDst, int xOffset);
        /// <summary>
        /// 绘制渐变色背景
        /// </summary>
        /// <param name="g">绘图面</param>
        /// <param name="prcDst"></param>
        /// <param name="offset"></param>
        public static void DrawGradientBg_SilverWhite_480(Graphics g, Rectangle prcDst, int offset)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                DrawGradientBg_SilverWhite_480(hdcDst, ref rect, offset);
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }
        /// <summary>
        /// 绘制渐变色背景——从上到下银色至白色
        /// </summary>
        /// <param name="hdcDst">设备上下文句柄</param>
        /// <param name="prcDst">待绘背景所在矩形</param>
        /// <param name="xOffset"></param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawGradientBg_SilverWhite_720Ex", SetLastError = true)]
        private static extern void DrawGradientBg_SilverWhite_720(IntPtr hdcDst, ref RECT prcDst, int xOffset);
        /// <summary>
        /// 绘制渐变色背景
        /// </summary>
        /// <param name="g">绘图面</param>
        /// <param name="prcDst">背景矩形</param>
        /// <param name="offset">偏移量</param>
        public static void DrawGradientBg_SilverWhite_720(Graphics g, Rectangle prcDst, int offset)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                DrawGradientBg_SilverWhite_720(hdcDst, ref rect, offset);
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }
        /// <summary>
        /// 绘制渐变矩形（从上到下渐变）
        /// </summary>
        /// <param name="hdcDst">目的DC </param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="cr1">渐变颜色 1</param>
        /// <param name="cr2">渐变颜色 2</param>
        /// <param name="ulMode">绘制模式：MZ_DRAW_GRAD_RECT_H, MZ_DRAW_GRAD_RECT_V  </param>
        /// <returns>返回true表示绘制成功；否则表示绘制失败</returns>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawGradRectEx", SetLastError = true)]
        private static extern bool DrawGradRect(IntPtr hdcDst, ref RECT prcDst, int cr1, int cr2, ulong ulMode);

        /// <summary>
        /// 绘制渐变矩形（从上到下渐变）
        /// </summary>
        /// <param name="g">绘图图面</param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="cr1">渐变颜色 1</param>
        /// <param name="cr2">渐变颜色 2</param>
        /// <param name="mode">绘制模式</param>
        /// <returns>返回true表示绘制成功；否则表示绘制失败</returns>
        public static bool DrawGradientRectangle(Graphics g, Rectangle prcDst, Color cr1, Color cr2, GradientDrawMode mode)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);
                return DrawGradRect(hdcDst, ref rect, GetRGB(cr1), GetRGB(cr2), (ulong)mode);
            }
            catch
            {
                return false;
            }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 绘制渐变矩形（上半和下半两个渐变）
        /// </summary>
        /// <param name="hdcDst">目的DC </param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="cr1">渐变颜色 1</param>
        /// <param name="cr2">渐变颜色 2</param>
        /// <param name="cr3">渐变颜色 3</param>
        /// <param name="cr4">渐变颜色 4</param>
        /// <param name="ulMode">绘制模式：MZ_DRAW_GRAD_RECT_H, MZ_DRAW_GRAD_RECT_V </param>
        /// <returns>返回true表示绘制成功；否则表示绘制失败</returns>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawGradRect2Ex", SetLastError = true)]
        private static extern bool DrawGradRect2(IntPtr hdcDst, ref RECT prcDst, int cr1, int cr2, int cr3, int cr4, ulong ulMode);
        /// <summary>
        /// 绘制渐变矩形（上半和下半两个渐变）
        /// </summary>
        /// <param name="hdc">目的DC </param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="cr1">渐变颜色 1</param>
        /// <param name="cr2">渐变颜色 2</param>
        /// <param name="c3">渐变颜色 3</param>
        /// <param name="c4">渐变颜色 4</param>
        /// <param name="mode">绘制模式</param>
        /// <returns>返回true表示绘制成功；否则表示绘制失败</returns>
        public static bool DrawGradientRectangle(Graphics g, Rectangle prcDst, Color cr1, Color cr2, Color cr3, Color cr4, GradientDrawMode mode)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);
                return DrawGradRect2(hdcDst, ref rect, GetRGB(cr1), GetRGB(cr2), GetRGB(cr3), GetRGB(cr4), (ulong)mode);
            }
            catch
            {
                return false;
            }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 绘制圆角渐变按钮（两个渐变）
        /// </summary>
        /// <param name="hdcDst">目的DC </param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="nRadius">圆角大小</param>
        /// <param name="cr1">渐变颜色 1</param>
        /// <param name="cr2">渐变颜色 2</param>
        /// <param name="cr3">渐变颜色 3</param>
        /// <param name="cr4">渐变颜色 4</param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawGradRoundButtonEx", SetLastError = true)]
        private static extern void DrawGradRoundButton(IntPtr hdcDst, ref RECT prcDst, int nRadius, int cr1, int cr2, int cr3, int cr4);
        /// <summary>
        /// 绘制圆角渐变按钮（两个渐变）
        /// </summary>
        /// <param name="g">绘图图面</param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="nRadius">圆角大小</param>
        /// <param name="cr1">渐变颜色 1</param>
        /// <param name="cr2">渐变颜色 2</param>
        /// <param name="cr3">渐变颜色 3</param>
        /// <param name="cr4">渐变颜色 4</param>
        public static void DrawGradRoundButton(Graphics g, Rectangle prcDst, int nRadius, Color cr1, Color cr2, Color cr3, Color cr4)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                int c1 = GetRGB(cr1);
                int c2 = GetRGB(cr2);
                int c3 = GetRGB(cr3);
                int c4 = GetRGB(cr4);

                RECT rect = RECT.FromRectangle(prcDst);

                DrawGradRoundButton(hdcDst, ref rect, nRadius, c1, c2, c3, c4);
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 画圆角矩形（从上至下渐变填充）
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcDst"></param>
        /// <param name="nRadius"></param>
        /// <param name="cr1"></param>
        /// <param name="cr2"></param>
        /// <param name="ulMode"></param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawGradRoundRectEx", SetLastError = true)]
        private static extern void DrawGradRoundRect(IntPtr hdcDst, ref RECT prcDst, int nRadius, int cr1, int cr2, uint ulMode);
        /// <summary>
        /// 画圆角矩形（从上至下渐变填充）
        /// </summary>
        /// <param name="g">绘图面</param>
        /// <param name="prcDst">矩形区域</param>
        /// <param name="nRadius">圆角半径</param>
        /// <param name="cr1">渐变色1</param>
        /// <param name="cr2">渐变色2</param>
        /// <param name="crTrans">透明色</param>
        public static void DrawGradRoundRect(Graphics g, Rectangle prcDst, int nRadius, Color cr1, Color cr2, GradientDrawMode drawMode)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                DrawGradRoundRect(hdcDst, ref rect, nRadius, GetRGB(cr1), GetRGB(cr2), (uint)drawMode);
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 画圆角矩形（上半和下半两个渐变）
        /// </summary>
        /// <param name="hdcDst">设备上下文句柄</param>
        /// <param name="prcDst">矩形区域</param>
        /// <param name="nRadius">圆角半径</param>
        /// <param name="cr1">渐变色1</param>
        /// <param name="cr2">渐变色2</param>
        /// <param name="cr3">渐变色3</param>
        /// <param name="cr4">渐变色4</param>
        /// <param name="crTrans">透明色</param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawGradRoundRect2Ex", SetLastError = true)]
        private static extern void DrawGradRoundRect2(IntPtr hdcDst, ref RECT prcDst, int nRadius, int cr1, int cr2, int cr3, int cr4, int crTrans);
        /// <summary>
        /// 画圆角矩形（上半和下半两个渐变）
        /// </summary>
        /// <param name="hdcDst">设备上下文句柄</param>
        /// <param name="prcDst">矩形区域</param>
        /// <param name="nRadius">圆角半径</param>
        /// <param name="cr1">渐变色1</param>
        /// <param name="cr2">渐变色2</param>
        /// <param name="cr3">渐变色3</param>
        /// <param name="cr4">渐变色4</param>
        /// <param name="crTrans">透明色</param>
        public static void DrawGradRoundRect2(Graphics g, Rectangle prcDst, int nRadius, Color cr1, Color cr2, Color cr3, Color cr4, Color crTrans)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                DrawGradRoundRect2(hdcDst, ref rect, nRadius, GetRGB(cr1), GetRGB(cr2), GetRGB(cr3), GetRGB(cr4), GetRGB(crTrans));
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 画渐变矩形（底部圆角）
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcDst"></param>
        /// <param name="nRadius"></param>
        /// <param name="cr1"></param>
        /// <param name="cr2"></param>
        /// <param name="crTrans"></param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawGradRoundRect_BottomEx", SetLastError = true)]
        private static extern void DrawGradRoundRect_Bottom(IntPtr hdcDst, ref RECT prcDst, int nRadius, int cr1, int cr2, int crTrans);
        /// <summary>
        /// 画渐变矩形（底部圆角）
        /// </summary>
        /// <param name="hdcDst">设备上下文句柄</param>
        /// <param name="prcDst">矩形区域</param>
        /// <param name="nRadius">圆角半径</param>
        /// <param name="cr1">渐变色1</param>
        /// <param name="cr2">渐变色2</param>
        /// <param name="crTrans">透明色</param>
        public static void DrawGradRoundRect_Bottom(Graphics g, Rectangle prcDst, int nRadius, Color cr1, Color cr2, Color crTrans)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                DrawGradRoundRect_Bottom(hdcDst, ref rect, nRadius, GetRGB(cr1), GetRGB(cr2), GetRGB(crTrans));
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 画渐变矩形（顶部圆角）
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcDst"></param>
        /// <param name="nRadius"></param>
        /// <param name="cr1"></param>
        /// <param name="cr2"></param>
        /// <param name="crTrans"></param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawGradRoundRect_TopEx", SetLastError = true)]
        private static extern void DrawGradRoundRect_Top(IntPtr hdcDst, ref RECT prcDst, int nRadius, int cr1, int cr2, int crTrans);
        /// <summary>
        /// 画渐变矩形（顶部圆角）
        /// </summary>
        /// <param name="hdcDst">设备上下文句柄</param>
        /// <param name="prcDst">矩形区域</param>
        /// <param name="nRadius">圆角半径</param>
        /// <param name="cr1">渐变色1</param>
        /// <param name="cr2">渐变色2</param>
        /// <param name="crTrans">透明色</param>
        public static void DrawGradRoundRect_Top(Graphics g, Rectangle prcDst, int nRadius, Color cr1, Color cr2, Color crTrans)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                DrawGradRoundRect_Top(hdcDst, ref rect, nRadius, GetRGB(cr1), GetRGB(cr2), GetRGB(crTrans));
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 画矩形
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcDst"></param>
        /// <param name="crPen">边线的颜色</param>
        /// <param name="crBrush">填充色</param>
        /// <returns></returns>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawRectEx", SetLastError = true)]
        private static extern bool DrawRect(IntPtr hdcDst, ref RECT prcDst, int crPen, int crBrush);
        /// <summary>
        /// 画矩形
        /// </summary>
        /// <param name="g">绘图面</param>
        /// <param name="prcDst">矩形区域</param>
        /// <param name="crPen">边线的颜色</param>
        /// <param name="crBrush">填充色</param>
        /// <returns>返回true表示绘制成功；否则表示绘制失败</returns>
        public static bool DrawRect(Graphics g, Rectangle prcDst, Color crPen, Color crBrush)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                return DrawRect(hdcDst, ref rect, GetRGB(crPen), GetRGB(crBrush));
            }
            catch
            {
                return false;
            }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 画圆角矩形
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcDst"></param>
        /// <param name="nRadius">圆角大小</param>
        /// <param name="crPen">边线的颜色</param>
        /// <param name="crBrush">填充色</param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawRoundRectEx", SetLastError = true)]
        private static extern void DrawRoundRect(IntPtr hdcDst, ref RECT prcDst, int nRadius, int crPen, int crBrush);
        /// <summary>
        /// 画圆角矩形
        /// </summary>
        /// <param name="g">绘图面</param>
        /// <param name="prcDst">矩形所在区域</param>
        /// <param name="nRadius">圆角大小</param>
        /// <param name="crPen">边线的颜色</param>
        /// <param name="crBrush">填充色</param>
        public static void DrawRoundRect(Graphics g, Rectangle prcDst, int nRadius, Color crPen, Color crBrush)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                DrawRoundRect(hdcDst, ref rect, nRadius, GetRGB(crPen), GetRGB(crBrush));
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 画矩形（底部圆角）
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcDst"></param>
        /// <param name="nRadius"></param>
        /// <param name="crPen"></param>
        /// <param name="crBrush"></param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawRoundRect_BottomEx", SetLastError = true)]
        private static extern void DrawRoundRect_Bottom(IntPtr hdcDst, ref RECT prcDst, int nRadius, int crPen, int crBrush);
        /// <summary>
        /// 画矩形（底部圆角）
        /// </summary>
        /// <param name="g">绘图面</param>
        /// <param name="prcDst">矩形区域</param>
        /// <param name="nRadius">圆角半径</param>
        /// <param name="crPen">画笔颜色</param>
        /// <param name="crBrush">画刷颜色</param>
        public static void DrawRoundRect_Bottom(Graphics g, Rectangle prcDst, int nRadius, Color crPen, Color crBrush)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                DrawRoundRect_Bottom(hdcDst, ref rect, nRadius, GetRGB(crPen), GetRGB(crBrush));
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 画矩形（顶部圆角） 
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcDst"></param>
        /// <param name="nRadius"></param>
        /// <param name="crPen"></param>
        /// <param name="crBrush"></param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "DrawRoundRect_TopEx", SetLastError = true)]
        private static extern void DrawRoundRect_Top(IntPtr hdcDst, ref RECT prcDst, int nRadius, int crPen, int crBrush);
        /// <summary>
        /// 画矩形（顶部圆角） 
        /// </summary>
        /// <param name="g">绘图面</param>
        /// <param name="prcDst">矩形所在区域</param>
        /// <param name="nRadius">圆角半径</param>
        /// <param name="crPen">画笔颜色</param>
        /// <param name="crBrush">画刷颜色</param>
        public static void DrawRoundRect_Top(Graphics g, Rectangle prcDst, int nRadius, Color crPen, Color crBrush)
        {
            IntPtr hdcDst = g.GetHdc();
            try
            {
                RECT rect = RECT.FromRectangle(prcDst);

                DrawRoundRect_Top(hdcDst, ref rect, nRadius, GetRGB(crPen), GetRGB(crBrush));
            }
            catch { }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 创建或获取Mask位图。已创建的位图将被缓冲，可以使用 ClearCachedRoundMaskBitmaps() 来删除它们 
        /// </summary>
        /// <param name="nRadius">圆角大小</param>
        /// <returns></returns>
        [DllImport("MZFCWrapper.dll", EntryPoint = "GetRoundMaskBitmapEx", SetLastError = true)]
        private static extern IntPtr MzGetRoundMaskBitmap(int nRadius);
        /// <summary>
        /// 创建或获取Mask位图。已创建的位图将被缓冲，可以使用 ClearCachedRoundMaskBitmaps() 来删除它们
        /// </summary>
        /// <param name="radius">半径</param>
        /// <returns>返回Mask位图</returns>
        public static Bitmap GetRoundMaskBitmap(int radius)
        {
            try
            {
                IntPtr hBitmap = MzGetRoundMaskBitmap(radius);

                return Bitmap.FromHbitmap(hBitmap);
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 复制源DC的图像到目的DC ( 水平竖直的平铺或拉伸 ) 
        /// </summary>
        /// <param name="hdcDst">目的DC </param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="hdcSrc">源DC </param>
        /// <param name="prcSrc">源矩形</param>
        /// <param name="nBltType">复制类型 (平铺: MZ_BLT_TYPE_TILE，拉伸: MZ_BLT_TYPE_STRETCH)</param>
        /// <param name="nEdgeLeft">左边缘的大小</param>
        /// <param name="nEdgeRight">右边缘的大小</param>
        /// <param name="nEdgeTop">顶部边缘的大小</param>
        /// <param name="nEdgeBottom">底部边缘的大小</param>
        /// <param name="bUseAlphaBlend">是否使用AlphaBlend进行复制</param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "MzBltEx", SetLastError = true)]
        private static extern bool MzBlt(IntPtr hdcDst, ref RECT prcDst, IntPtr hdcSrc, ref RECT prcSrc, int nBltType,
            int nEdgeLeft, int nEdgeRight, int nEdgeTop, int nEdgeBottom, bool bUseAlphaBlend);
        /// <summary>
        /// 复制源DC的图像到目的DC ( 水平竖直的平铺或拉伸 ) 
        /// </summary>
        /// <param name="g">绘图图面</param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="hdcSrc">源DC </param>
        /// <param name="prcSrc">源矩形</param>
        /// <param name="bltType">复制类型 (平铺: MZ_BLT_TYPE_TILE，拉伸: MZ_BLT_TYPE_STRETCH)</param>
        /// <param name="edgeLeft">左边缘的大小</param>
        /// <param name="edgeRight">右边缘的大小</param>
        /// <param name="edgeTop">顶部边缘的大小</param>
        /// <param name="edgeBottom">底部边缘的大小</param>
        /// <param name="useAlphaBlend">是否使用AlphaBlend进行复制</param>
        public static bool MzBlt(Graphics g, Rectangle prcDst, IntPtr hdcSrc, Rectangle prcSrc, MzBltType bltType, int edgeLeft, int edgeRight, int edgeTop, int edgeBottom, bool useAlphaBlend)
        {
            IntPtr hdcDst = g.GetHdc();

            RECT rectDst = RECT.FromRectangle(prcDst);
            RECT rectSrc = RECT.FromRectangle(prcSrc);

            try
            {
                return MzBlt(hdcDst, ref rectDst, hdcSrc, ref rectSrc, (int)bltType, edgeLeft, edgeTop, edgeRight, edgeBottom, useAlphaBlend);
            }
            catch (System.Exception ex)
            {
                return false;	
            }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 复制源DC的图像到目的DC ( 水平平铺或拉伸 )
        /// </summary>
        /// <param name="hdcDst">目的DC </param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="hdcSrc">源DC </param>
        /// <param name="prcSrc">源矩形</param>
        /// <param name="nBltType">复制类型 (平铺: MZ_BLT_TYPE_TILE，拉伸: MZ_BLT_TYPE_STRETCH)</param>
        /// <param name="nEdge1">左边缘的大小</param>
        /// <param name="nEdge2">右边缘的大小</param>
        /// <param name="bUseAlphaBlend">是否使用AlphaBlend进行复制</param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "MzBlt_HEx", SetLastError = true)]
        public static extern bool MzBlt_H(IntPtr hdcDst, ref RECT prcDst, IntPtr hdcSrc, ref RECT prcSrc, int nBltType,
            int nEdge1, int nEdge2, bool bUseAlphaBlend);
        /// <summary>
        /// 复制源DC的图像到目的DC ( 水平平铺或拉伸 )
        /// </summary>
        /// <param name="g">绘图图面</param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="hdcSrc">源DC </param>
        /// <param name="prcSrc">源矩形</param>
        /// <param name="bltType">复制类型 (平铺: MZ_BLT_TYPE_TILE，拉伸: MZ_BLT_TYPE_STRETCH)</param>
        /// <param name="edge1">左边缘的大小</param>
        /// <param name="edge2">右边缘的大小</param>
        /// <param name="useAlphaBlend">是否使用AlphaBlend进行复制</param>
        public static bool MzBlt_H(Graphics g, Rectangle prcDst, IntPtr hdcSrc, Rectangle prcSrc, MzBltType bltType,
            int edge1, int edge2, bool useAlphaBlend)
        {
            IntPtr hdcDst = g.GetHdc();

            RECT rectDst = RECT.FromRectangle(prcDst);
            RECT rectSrc = RECT.FromRectangle(prcSrc);

            try
            {
                return MzBlt_H(hdcDst, ref rectDst, hdcSrc, ref rectSrc, (int)bltType, edge1, edge2, useAlphaBlend);
            }
            catch
            {
                return false;
            }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 复制源DC的图像到目的DC ( 竖直平铺或拉伸 ) 
        /// </summary>
        /// <param name="hdcDst">目的DC </param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="hdcSrc">源DC </param>
        /// <param name="prcSrc">源矩形</param>
        /// <param name="nBltType">复制类型 (平铺: MZ_BLT_TYPE_TILE，拉伸: MZ_BLT_TYPE_STRETCH)</param>
        /// <param name="nEdge1">顶部边缘的大小</param>
        /// <param name="nEdge2">底部边缘的大小</param>
        /// <param name="bUseAlphaBlend">是否使用AlphaBlend进行复制</param>
        [DllImport("MZFCWrapper.dll", EntryPoint = "MzBlt_VEx", SetLastError = true)]
        private static extern bool MzBlt_V(IntPtr hdcDst, ref RECT prcDst, IntPtr hdcSrc, ref RECT prcSrc, int nBltType,
            int nEdge1, int nEdge2, bool bUseAlphaBlend);
        /// <summary>
        /// 复制源DC的图像到目的DC ( 竖直平铺或拉伸 ) 
        /// </summary>
        /// <param name="g">绘图图面</param>
        /// <param name="prcDst">目的矩形</param>
        /// <param name="hdcSrc">源DC </param>
        /// <param name="prcSrc">源矩形</param>
        /// <param name="bltType">复制类型 (平铺: MZ_BLT_TYPE_TILE，拉伸: MZ_BLT_TYPE_STRETCH)</param>
        /// <param name="edge1">顶部边缘的大小</param>
        /// <param name="edge2">底部边缘的大小</param>
        /// <param name="useAlphaBlend">是否使用AlphaBlend进行复制</param>
        public static bool MzBlt_V(Graphics g, Rectangle prcDst, IntPtr hdcSrc, Rectangle prcSrc, MzBltType bltType,
            int edge1, int edge2, bool useAlphaBlend)
        {
            IntPtr hdcDst = g.GetHdc();

            RECT rectDst = RECT.FromRectangle(prcDst);
            RECT rectSrc = RECT.FromRectangle(prcSrc);

            try
            {
                return MzBlt_V(hdcDst, ref rectDst, hdcSrc, ref rectSrc, (int)bltType, edge1, edge2, useAlphaBlend);
            }
            catch (System.Exception ex)
            {
                return false;
            }
            finally
            {
                g.ReleaseHdc(hdcDst);
            }
        }

        /// <summary>
        /// 清除渐变背景缓冲的资源
        /// </summary>
        [DllImport("MZFCWrapper.dll", EntryPoint = "UnLoadGradientBgResourceEx", SetLastError = true)]
        public static extern void UnLoadGradientBgResource();
    }
}
